package com.ydd.network.http;

import com.taofengsdk.okhttp.CommonOkHttpClient;
import com.taofengsdk.okhttp.listener.DisposeDataHandle;
import com.taofengsdk.okhttp.listener.DisposeDataListener;
import com.taofengsdk.okhttp.listener.DisposeDownloadListener;
import com.taofengsdk.okhttp.request.CommonRequest;
import com.taofengsdk.okhttp.request.RequestParams;
import com.ydd.model.story.BaseStoryModel;
import com.ydd.model.recommand.BaseRecommandModel;
import com.ydd.model.update.UpdateModel;
import com.ydd.model.user.User;

/**
 * Created by tao on 17-3-13.
 */

public class RequestCenter {

    private static void postRequest(String url, RequestParams params, Class<?> clazz
            , DisposeDataListener listener
    ) {
        CommonOkHttpClient.get(CommonRequest.createGetRequest(url, params)
                , new DisposeDataHandle(listener, clazz));

    }


    public static void requestRecommanData(DisposeDataListener listener) {
        RequestCenter.postRequest(HttpConstans.HOME_RECOMMAND, null, BaseRecommandModel.class, listener);
    }

    public static void requestCheckVersion(DisposeDataListener listener) {
        RequestCenter.postRequest(HttpConstans.CHECK_UPDATE, null, UpdateModel.class, listener);
    }

    public static void requestUserLogin(String userName, String password, DisposeDataListener listener) {
        RequestParams params = new RequestParams();
        params.put("name", userName);
        params.put("password", password);

        RequestCenter.postRequest(HttpConstans.LOGIN, params, User.class, listener);
    }

    public static void downloadFile(String url,String path,DisposeDownloadListener listener){
        CommonOkHttpClient.downloadFile(CommonRequest.createGetRequest(url,null),
                new DisposeDataHandle(listener,path));

    }

    /**
     * 请求课程详情
     *
     * @param listener
     */

    public static void requestStoryDetail(String storyId, DisposeDataListener listener) {
        RequestParams params = new RequestParams();
        params.put("storyId", storyId);
        RequestCenter.postRequest(HttpConstans.COURSE_DETAIL, params,  BaseStoryModel.class,listener);
    }
}
